﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Windows.Forms;
using SharppiFlowEditor.models;
using SharppiFlowEditor.views;

namespace SharppiFlowEditor
{
    public class SharppiApp
    {
        [STAThread]
        public static void Main()
        {
            // Application settings
            Application.EnableVisualStyles();

            // Model and view for the application
            AppModel appModel = new AppModel();
            AppView appView = new AppView(appModel);
            //AppForm df = new AppForm(appModel);

            // Run application
            try
            {
                CheckAppFiles();
                Application.Run(appView);
            }
            catch (AppFileCheckException ex)
            {
                DialogResult dialog = MessageBox.Show(
                    "Some of the application files are missing. The application will be closed.",
                    "Fatal error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                if (dialog.Equals(DialogResult.OK))
                {
                    Application.Exit();
                }
            }
        }

        public static void CheckAppFiles()
        {
            List<string> files = new List<string>();

            files.Add("\\img\\nodeTool.png");
            files.Add("\\img\\connectorTool.png");
            files.Add("\\img\\eraserTool.png");

            foreach (string file in files)
            {
                if (!File.Exists(Application.StartupPath + file))
                {
                    throw new AppFileCheckException();
                }
            }
        }
    }

    class AppFileCheckException : Exception
    {

    }
}
